﻿using System;
using System.Diagnostics;
using System.IO;
using Microsoft.Data.Schema.SchemaModel;
using Microsoft.Data.Schema.Sql.SchemaModel;
using Microsoft.Data.Schema.StaticCodeAnalysis;
using Microsoft.Data.Schema;
using System.Collections;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using Microsoft.Data.Schema.ScriptDom.Sql;

namespace Neznayka
{
    public class CTEUtil : SQLObjectFragment
    {

        private List<Identifier> _ExpressionNames;
        private List<String> _ExpressionNamesAsStrings;

        #region ctor
        public CTEUtil()
        {
            _ExpressionNames = new List<Identifier>();
            _ExpressionNamesAsStrings = new List<String>();
        }
        public CTEUtil( int FirstTokenIndex
                      , int LastTokenIndex
                      , int StartOffset
                      , int FragmentLength
                      )
            : base(FirstTokenIndex, LastTokenIndex, StartOffset, FragmentLength)
        {
            _ExpressionNames = new List<Identifier>();
            _ExpressionNamesAsStrings = new List<String>();
        }

        #endregion

        #region properties
        public ReadOnlyCollection<Identifier> ExpressionNames
        {
            get
            {
                return _ExpressionNames.AsReadOnly();
            }
        }
        public ReadOnlyCollection<String> ExpressionNamesAsStrings
        {
            get
            {
                return _ExpressionNamesAsStrings.AsReadOnly();

            }
        }

        #endregion

        #region methods

        public void Add(Identifier identifier)
        {
            // <pex>
            if (identifier == (Identifier)null)
                throw new ArgumentNullException("identifier");
            // </pex>
            _ExpressionNames.Add(identifier);
            _ExpressionNamesAsStrings.Add(identifier.Value);

            //using (StreamWriter w = File.AppendText(@"c:\temp\UpdateCTE_log.txt"))
            //{
            //    w.WriteLine(@"stored cte:- ");
            //    w.WriteLine(identifier.Value);
            //    w.Close();
            //}
        }
        #endregion


    }
}